import {Component, OnInit} from '@angular/core';
import {LoadingService} from '../../../shared/loading.service';
import {AlertService} from '../../../shared/alert.service';
import {RechargeRecordService} from '../recharge-record.service';
import {ActivatedRoute} from '@angular/router';

@Component({
    selector: 'app-recharge-view',
    templateUrl: './recharge-view.component.html',
    styleUrls: ['./recharge-view.component.scss']
})
export class RechargeViewComponent implements OnInit {

    public dataList: any = [];
    public id: any = '';

    constructor(public loading: LoadingService,
                public service: RechargeRecordService,
                public alert: AlertService,
                public router: ActivatedRoute) {
    }

    ngOnInit() {
        this.router.params.subscribe(params => {
            this.id = params.id;
        });
        // this.getData();
    }

    // 获取列表数据
    getData() {
        this.loading.show();
        const params: any = {
            token: localStorage.token,
        };
        console.log(params);
        this.service.getList(params).subscribe(
            res => {
                console.log(res, '数据');
                if (res['code'] === 0) {
                    this.dataList = res['data'];
                    this.loading.hide();
                } else {
                    this.loading.hide();
                    this.alert.show(res['msg'])
                }
            },
            error => {
                this.loading.hide();
                this.alert.show('网络错误');
            }
        );
    }

    back() {
        window.history.go(-1);
    }
}
